#ifndef _WINPLAYER_H_
#define _WINPLAYER_H_

#include <string>
#include <Windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <wmp.h>

#undef GetCurrentTime

#include "Player.h"

// winamp
class CWinAmpPlayer : public CPlayer
{
public:
	virtual bool IsOpen();
	virtual std::string GetMediaTitle();
	virtual int GetCurrentTime();
};

//// iTunes
//class CITunesPlayer : 
//	public CPlayer,
//	public _IiTunesEvents
//{
//
//	CComPtr<IiTunes> m_spITunes;
//
//	bool m_isInited;
//	bool init();
//	void OniTunesClose();
//
//	ITypeInfo* m_pITypeInfo;
//	long m_dwRefCount;
//public:
//	CITunesPlayer();
//	virtual ~CITunesPlayer();
//
//	virtual bool IsOpen();
//	virtual std::string GetMediaTitle();
//	virtual int GetCurrentTime();
//
//public:
//
//	ULONG STDMETHODCALLTYPE AddRef();
//	ULONG STDMETHODCALLTYPE Release();
//	HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject);
//	HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* pctinfo);
//	HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
//	HRESULT STDMETHODCALLTYPE GetIDsOfNames(  
//		const IID& iid,
//		OLECHAR** arrayNames,
//		UINT countNames,
//		LCID,          // Localization is not supported.
//		DISPID* arrayDispIDs);
//	HRESULT STDMETHODCALLTYPE Invoke(DISPID dispidMember, REFIID riid,
//		LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
//		EXCEPINFO* pexcepinfo, UINT* puArgErr);
//};

// windows media player
class CWmpPlayer : public CPlayer
{
	class CRemoteHost : 
		public CComObjectRootEx<CComSingleThreadModel>, 
		public IServiceProvider, 
		public IWMPRemoteMediaServices  
	{
	public:
		CRemoteHost();
		virtual ~CRemoteHost();

		//DECLARE_PROTECT_FINAL_CONSTRUCT()

		BEGIN_COM_MAP(CRemoteHost)
			COM_INTERFACE_ENTRY(IServiceProvider)
			COM_INTERFACE_ENTRY(IWMPRemoteMediaServices)
		END_COM_MAP()

		// IServiceProvider
		STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void ** ppv);
		// IWMPRemoteMediaServices
		STDMETHOD(GetServiceType)(BSTR * pbstrType);
		STDMETHOD(GetApplicationName)(BSTR * pbstrName);
		STDMETHOD(GetScriptableObject)(BSTR * pbstrName, IDispatch ** ppDispatch);
		STDMETHOD(GetCustomUIMode)(BSTR * pbstrFile);
	};

	CComModule _Module;
	HWND m_hwnd;

	CComPtr<IWMPPlayer4> m_spPlayer;
	CAxWindow *m_pView;

	bool CreateWnd();
	bool InitRemotePlayer();

	int Stop();
public:
	CWmpPlayer();
	~CWmpPlayer();

	virtual bool IsOpen();
	virtual std::string GetMediaTitle();
	virtual int GetCurrentTime();

};
#endif